package MetaInit

import (
	"database/sql"
	"db2s/Er"
	"db2s/arg"
	"db2s/dbExec"
	"db2s/global"
)

type (
	TableFilter struct {
		LogSeq         int64
		MapTables      map[string]string //映射信息
		TableJoinFay   string            //表校验方式
		tp             *TableMapStrconv
		TableMetaData  map[string]Er.TablesMetaInfoEr
		TableDataQuery map[string]dbExec.IndexColumnStruct
		SourceDrive    string
		DestDrive      string
		SDB            map[string]*sql.DB
		DDB            map[string]*sql.DB
		//Input          global.StartPartConfigInputP
		SqlTimeOut   int
		SqlMode      bool
		IgnoreTables string //忽略表
		IgDest       bool   //是否忽略目标端检查
	}

	TableMeta struct {
		TableList      []string
		TableMiss      []string
		tp             *TableMapStrconv
		Cap            int
		LogSeq         int64
		HiddenIndex    bool //是否查询隐藏索引，目前只有cluster有
		TableMetaData  map[string]Er.TablesMetaInfoEr
		TableDataQuery map[string]dbExec.IndexColumnStruct
		SDB            map[string]*sql.DB
		DDB            map[string]*sql.DB
		Input          global.StartPartConfigInputP
		Schema         arg.SchemaS
		DSns           arg.DSNsS
		Rules          arg.RulesS
		IgDest         bool
	}
	TableNameMeta struct {
		Schema string
		Table  string
		Exist  string
	}
	TableStructMeta struct {
		ColumnM []map[string] /*column AS*/ string /*columnName*/ //column metaData
		ColumnS map[string] /*columnSeq*/ string   /*columnName*/ //column seq
		Type    string                             //source or dest
	}
	TableStructMetaDataSum struct {
		SColumnMSum map[string]TableStructMeta
		DColumnMSum map[string]TableStructMeta
		ColumnSeq   map[string]string
	}
	TableMapStrconv struct {
		TableMap   map[string]string
		Schema     string
		Table      any
		ResultType string /*schema返回库名，table表示返回表名，all返回schema+table*/
	}
	// SchemaInitObject 单个任务组的表对象
	SchemaInitObject struct {
		TableList     []string
		TableMiss     []string
		TableMap      map[string]string
		TaskTableList []*SchemaInitObject
	}
	// SchemaInitFilter 执行计划上下文
	schemaGroupFilter struct {
		TableList     []string
		TableMap      map[string]string
		TaskTableList []*schemaGroupFilter
	}
	IndexChooseResult struct {
		IndexType     string            `json:"index type"`     //索引类型
		IndexColumn   []string          `json:"index column"`   //索引列集合
		IndexName     string            `json:"index name"`     //索引名
		ColumnSeq     map[string]string `json:"column seq"`     //索引列序号
		Cardinality   string            `json:"cardinality"`    //索引的离散度
		IndexCategory string            `json:"index category"` //索引角色
	}
)

var (
	WriteLog = global.LogWrite.MainL
)

func GetTableFilterO() *TableFilter {
	return &TableFilter{tp: &TableMapStrconv{}}
}
func GetSchemaObject() *SchemaInitObject {
	return &SchemaInitObject{}
}
func GetTableStrconvO() *TableMapStrconv {
	return &TableMapStrconv{}
}
func GetMetaDataO() *TableMeta {
	return &TableMeta{}
}
